<?php namespace Summer\Userhub\Updates;

use Schema;
use Winter\Storm\Database\Updates\Migration;

class UserAddHjdFields extends Migration
{
    public function up()
    {
        if (Schema::hasColumns('users', [
            'tuid',
            'tids',
            'tdeep',
            'num_zt',
            'num_td'
        ])) {
            return;
        }

        Schema::table('users', function($table)
        {
            $table->integer('tuid')->unsigned()->nullable()->default(0);//推荐人id
            $table->longText('tids')->nullable()->default(NULL);//推荐ids
            $table->integer('tdeep')->unsigned()->nullable()->default(0);//推荐深度
            $table->integer('num_zt')->unsigned()->nullable()->default(0);//直推人数
            $table->integer('num_td')->unsigned()->nullable()->default(0);//团队人数
        });
    }

    public function down()
    {
        if (Schema::hasTable('users')) {
            Schema::table('users', function ($table) {
                $table->dropColumn([
                    'tuid',
                    'tids',
                    'tdeep',
                    'num_zt',
                    'num_td'
                ]);
            });
        }
    }
}
